package system

import (
	"encoding/json"
	"sensitives/service/dic"
	"strconv"

	"github.com/gin-gonic/gin"
)

type pushmsg struct {
	commonfilter
}

var Pushmsg pushmsg

func (pmsg *pushmsg) Check(context *gin.Context) {
	siteid, _ := strconv.Atoi(context.Param("siteid"))
	message := context.PostForm("message")
	pmsg.Sensitiveword = make([]sensitive, 0)
	type OutPut struct {
		Code bool        `json:"code"`
		Data []sensitive `json:"data"`
	}
	if message == "" {
		output := OutPut{Code: false, Data: pmsg.Sensitiveword}
		stive_sys, _ := json.Marshal(output)
		context.Writer.Write(stive_sys)
		return
	}
	site_sys_dic := dic.CloudMap[siteid].Sys
	pmsg.filter(message, "message", &site_sys_dic)
	output := OutPut{Code: true, Data: pmsg.Sensitiveword}
	stive_sys, _ := json.Marshal(output)
	context.Writer.Write(stive_sys)
}
